package com.ruoyi.project.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.BusinessHarvest;
import com.ruoyi.project.business.service.IBusinessHarvestService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 收成Controller
 * 
 * @author ruoyi
 * @date 2020-10-22
 */
@RestController
@RequestMapping("/business/harvest")
public class BusinessHarvestController extends BaseController
{
    @Autowired
    private IBusinessHarvestService businessHarvestService;

    /**
     * 查询收成列表
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessHarvest businessHarvest)
    {
        startPage();
        List<BusinessHarvest> list = businessHarvestService.selectBusinessHarvestList(businessHarvest);
        return getDataTable(list);
    }

    /**
     * 导出收成列表
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:export')")
    @Log(title = "收成", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BusinessHarvest businessHarvest)
    {
        List<BusinessHarvest> list = businessHarvestService.selectBusinessHarvestList(businessHarvest);
        ExcelUtil<BusinessHarvest> util = new ExcelUtil<BusinessHarvest>(BusinessHarvest.class);
        return util.exportExcel(list, "harvest");
    }

    /**
     * 获取收成详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(businessHarvestService.selectBusinessHarvestById(id));
    }

    /**
     * 新增收成
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:add')")
    @Log(title = "收成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessHarvest businessHarvest)
    {
        return toAjax(businessHarvestService.insertBusinessHarvest(businessHarvest));
    }

    /**
     * 修改收成
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:edit')")
    @Log(title = "收成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessHarvest businessHarvest)
    {
        return toAjax(businessHarvestService.updateBusinessHarvest(businessHarvest));
    }

    /**
     * 删除收成
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:remove')")
    @Log(title = "收成", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(businessHarvestService.deleteBusinessHarvestByIds(ids));
    }


    /**
     * 获取收成详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:harvest:query')")
    @GetMapping(value = "/getinfobyservice")
    public AjaxResult getinfobyservice(Long serviceOrderId)
    {
        return AjaxResult.success(businessHarvestService.getinfobyservice(serviceOrderId));
    }

}
